﻿#include<iostream>
using namespace std;
class Person {
public:
	Person(const char* name)
		:_name(name)
	{}
	Person(const Person& p) {
		_name = p._name;
	}
	Person& operator=(const Person& p) {
		_name = p._name;
		return *this;
	}
	string _name;//姓名
	static int _cnt;
};
int Person::_cnt = 1;

class Student :public Person {
public:
	Student(const char* name,string id)
		:Person(name)
		,_No(id){}
	Student(const Student& s)
		:Person(s),
		_No(s._No)
	{}
	Student& operator=(const Student& s) {
		if (this != &s) {
			Person::operator=(s);
			_No = s._No;
		}
		else {
			return *this;
		}
	}
private:
	string _No; //学号
};
int main(){
	Person p("z");
	Student s1("l","2024");
	Student s2(s1);
	Student s3("w", "2023");
	// 结果可以看到⾮静态成员_name的地址是不⼀样的
    // 说明派生类继承下来了，基类 派生类对象各有⼀份
	cout << &s1._name << endl;
	cout << &s2._name << endl;
	cout << &s3._name << endl;
	cout << &p._name << endl;

	cout << endl;
	// 这⾥的运⾏结果可以看到静态成员_count的地址是⼀样的
	// 说明派⽣类和基类共⽤同⼀份静态成员
	cout << &p._cnt << endl;
	cout << &s1._cnt << endl;
	cout << &s2._cnt << endl;
	cout << &s3._cnt << endl;

	return 0;
}